Math.pow()

Доступность

Flash Player 5. Во Flash Player 4 методы и свойства класса Math эмулируются при помощи приближенных вычислений и могут быть не так точны, как во Flash Player 5 и более поздних.

Синтаксис

Math.pow(x:Number , y:Number) : Number

Параметры

x Основание степени.

y Показатель степени x (степень, в которую возводится основание).

Возвращает

Число.

Описание

Метод; вычисляет и возвращает x в степени y.

Пример

В следующем примере Math.pow и Math.sqrt используются для вычисления длины линии.

this.createEmptyMovieClip("canvas_mc", this.getNextHighestDepth());
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
  this.origX = _xmouse;
  this.origY = _ymouse;
};
mouseListener.onMouseUp = function() {
  this.newX = _xmouse;
  this.newY = _ymouse;
  var minY = Math.min(this.origY, this.newY);
  var nextDepth:Number = canvas_mc.getNextHighestDepth();
  var line_mc:MovieClip = canvas_mc.createEmptyMovieClip("line"+nextDepth+"_mc", nextDepth);
  line_mc.moveTo(this.origX, this.origY);
  line_mc.lineStyle(2, 0x000000, 100);
  line_mc.lineTo(this.newX, this.newY);
  var hypLen:Number = Math.sqrt(Math.pow(String_mc._width, 2)+Math.pow(String_mc._height, 2));
  line_mc.createTextField("length"+nextDepth+"_txt", canvas_mc.getNextHighestDepth(), this.origX, this.origY-22, 100, 22);
  line_mc['length'+nextDepth+'_txt'].text = Math.round(hypLen) +" пикселов";
};
Mouse.addListener(mouseListener);